package com.itstherules.jmsunit.managers;

import com.itstherules.jmsunit.queuemanager.activemq.ActiveMQQueueManager;

public class QueueManagersFactory {

	public enum QueueManagerType {
		ActiveMQ(""), WebsphereMQ("com.itstherules.jmsunit.queuemanager.webspheremq.WebSphereMQQueueManager");
		private final String className;

		QueueManagerType(String className){
			this.className = className;
		}
		@Override
		public String toString() {
			return className;
		}
	}

	public static QueueManager create(String uri, QueueManagerType queueManagerType) throws Exception {
		switch (queueManagerType) {
			case ActiveMQ:
				return new ActiveMQQueueManager(uri);
			case WebsphereMQ:
				String className = QueueManagerType.WebsphereMQ.toString();
				try {
					QueueManager queueManager = (QueueManager) Class.forName(className).getConstructor(String.class).newInstance(uri);
					return queueManager;
				} catch(Exception e) {
					throw new AssertionError("Class "+className+" not found");
				}
			default:
				throw new AssertionError("QueueManager not recognised");
		}
	}
	
}
